<?php

namespace app\yy\admin;

use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use think\Db;

class Wpimg extends Admin
{
    public $status = [
        '0' => '待迁移:default',
        '1' => '迁移成功:success',
        '2' => '迁移中:primary',
        '3' => '迁移失败:danger'
    ];

    public function index()
    {
        $map = $this->getMap();
        $data_list = Db::name('wp_images')->where($map)->order('id desc')->paginate();
        // 使用ZBuilder快速创建数据表格
        return ZBuilder::make('table')
            ->setPageTitle('WP图片列表') // 设置页面标题
            ->setTableName('wp_images') // 设置数据表名
            ->setSearchArea([
                ['select', 'status', '状态', '', '', $this->status],
                ['text', 'sku', '商品sku', 'like'],
                ['text', 'image', 'YY图片', 'like']
            ])
            ->addColumns([ // 批量添加列
                ['id', 'ID'],
                ['sku', '商品SKU'],
                ['image', '原图片'],
                ['web_dir', '本地路径'],
                ['local_path', '本地图片'],
                ['status', '状态', 'status', '', $this->status],
                ['remark', '备注'],
                ['right_button', '操作', 'btn']
            ])
            ->addTopButton('disable',['title' => '重新处理']) // 批量添加顶部按钮
//            ->replaceRightButton(['status' => 1], '','disable')
            ->addRightButton('disable',['title' => '重新处理']) // 批量添加右侧按钮
            ->setRowList($data_list) // 设置表格数据
            ->setColumnWidth([
                '_checkbox' => 10,
                'id' => 15,
                'sku' => 40,
                'local_path' => 50,
                'remark' => 45,
                'status' => 25,
                'right_button' => 20,
            ])
            ->fetch(); // 渲染页面
    }
}